package com.luhongzhe.data;

import java.util.ArrayList;

import com.luhongzhe.config.Config;

import android.graphics.Point;

/**
 * @author luhongzhe
 *         email: azhe0660@gmail.com
 *         qq:	 360849771
 * @date 2011-6-16
 */

public class LStatePoint
{
	private double x;
	private double y;
	
	private ArrayList<LStateLine> lines = new ArrayList<LStateLine>();
	
	public LStatePoint(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	
	public LStatePoint(LStatePoint point)
	{
		this.x = point.x;
		this.y = point.y;
	}
	
	public void destroy()
	{
		lines.clear();
	}
	
	public LPoint createPoint()
	{
		return new LPoint(x, y);
	}
	
	public boolean hasLine(LStateLine line)
	{
		int size = lines.size();
		for (int i = 0; i < size; i++)
		{
			if (line == lines.get(i))
				return true;
		}
		
		return false;
	}
	
	public void removeLine(LStateLine line)
	{
		lines.remove(line);
	}
	
	public void addLine(LStateLine line)
	{
		lines.add(line);
	}
	
	public double getX()
	{
		return x;
	}
	
	public double getY()
	{
		return y;
	}
	
	public int getIntX()
	{
		return (int)x;
	}
	
	public int getIntY()
	{
		return (int)y;
	}
	
	public String toString()
	{
		return "x = " + getX() + "  y = " + getY();
	}
	
	public boolean isEqual(LStatePoint point)
	{
		return (getX() == point.getX()) && (getY() == point.getY());
	}
	
	public boolean isClose(LStatePoint point)
	{
		return isClose(point.x, point.y);
	}
	
	public boolean isClose(double x, double y)
	{
		return getDistance(x, y) < Config.POINT_DISTANCE_TOLERANCE;
	}
	
	public static double getDistance(LStatePoint p1, LStatePoint p2)
	{
		return getDistance(p1.getX(), p1.getY(), p2.getX(), p2.getY());
	}
	
	public static double getDistance(double x1, double y1, double x2, double y2)
	{
		return (double)Math.hypot((x2 - x1) , (y2 - y1));      
	}
	
	public double getDistance(double x, double y)
	{
		return getDistance(getX(), getY(), x, y);
	}
	
	
}
